﻿using System;
using System.Linq;
using System.Windows;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
using Mipic.Infrastructure.Services;
using Mipic.Modules.Epoc;
using Mipic.Modules.Interactions;
using Mipic.Modules.Mood;
using Mipic.Moduls.Filters;

namespace Mipic
{
    public class Bootstrapper : UnityBootstrapper
    {
        /// <summary>
        /// Creates the shell or main window of the application.
        /// </summary>
        /// <remarks>
        /// If the returned instance is a <see cref="T:System.Windows.DependencyObject" />,
        /// the
        /// <see cref="T:Microsoft.Practices.Prism.Bootstrapper" /> will attach the default
        /// <seealso cref="T:Microsoft.Practices.Prism.Regions.IRegionManager" /> of
        /// the application in its <see cref="F:Microsoft.Practices.Prism.Regions.RegionManager.RegionManagerProperty" />
        /// attached property
        /// in order to be able to add regions by using the <seealso cref="F:Microsoft.Practices.Prism.Regions.RegionManager.RegionNameProperty" />
        /// attached property from XAML.
        /// </remarks>
        /// <returns>The shell of the application.</returns>
        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<Shell>();
        }

        /// <summary>
        /// Initializes the shell.
        /// </summary>
        protected override void InitializeShell()
        {
            Application.Current.MainWindow = Shell as Window;
            Application.Current.MainWindow.Show();
        }

        /// <summary>
        /// Creates the <see cref="T:Microsoft.Practices.Prism.Modularity.IModuleCatalog" />
        /// used by Prism.
        /// </summary>
        /// <remarks>
        /// The base implementation returns a new ModuleCatalog.
        /// </remarks>
        /// <returns></returns>
        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog();
            catalog.AddModule(typeof(EpocModule));
            catalog.AddModule(typeof(FilterModule));
            catalog.AddModule(typeof(InteractionModule));
            catalog.AddModule(typeof(MoodModule));

            return catalog;
        }

        /// <summary>
        /// Configures the <see cref="T:Microsoft.Practices.Unity.IUnityContainer" />. May
        /// be overwritten in a derived class to add specific
        /// type mappings required by the application.
        /// </summary>
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            RegisterTypeIfMissing(typeof(IOpenFileDialogService), typeof(ModalOpenFileDialog), true);
        }
    }
}
